import { createApp } from "vue";
import { setupRouter } from "@/router";
import { createPinia } from "pinia";

import { useTagStore } from "@/store/modules/tag";
import { useArticleStore } from "@/store/modules/article";
import "@/router/routes";
import RightMenuDirective from "./directives/rightClick";
import App from "./App.vue";
import "@/styles/index.scss";
const app = createApp(App);

function bootstrap() {
  const pinia = createPinia();
  setupRouter(app);
  app.use(RightMenuDirective);
  app.use(pinia);
  const tagStore = useTagStore();
  const articleStore = useArticleStore();

  app.mount("#app");
  app.onUnmount(() => {
    articleStore.clearCurrentArticle();
    tagStore.clearAllTags();
  });
}
bootstrap();

// window.addEventListener("beforeunload", app.unmount);
